
#import "LLDiscoverController.h"
#import "LLSearchView.h"
#import "LLDefaultView.h"
#define kSearchViewMargin 40
@interface LLDiscoverController ()<UITextFieldDelegate>
@property (nonatomic, weak) LLSearchView *searchView;
@end

@implementation LLDiscoverController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 自定义搜索框
    [self setupSearchView];
    
}

/**
 *  自定义搜索框
 */
- (void)setupSearchView{
    
    LLSearchView *searchView = [[LLSearchView alloc] init];
    searchView.delegate = self;
    searchView.size = CGSizeMake(self.view.width - 2 * kSearchViewMargin, 30);
    searchView.borderStyle = UITextBorderStyleRoundedRect;
    self.navigationItem.titleView = searchView;
    self.searchView = searchView;
}

#pragma mark - UITextFieldDelegate
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    
    self.searchView.leftIconName = @"settings_statistic_triangle";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancle)];
}

- (void)cancle{
    
    // 1.关闭键盘
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
    self.navigationItem.rightBarButtonItem = nil;
    self.searchView.leftIconName = @"searchbar_searchlist_search_icon";
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    
//    [self.tableView endEditing:YES];
//    [self.searchView resignFirstResponder];
    // 1.关闭键盘
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
    self.searchView.leftIconName = @"searchbar_searchlist_search_icon";
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    // 1.关闭键盘
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}

@end
